package net.scrumtool.view;

import net.scrumtool.technics.Utils;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

public class Connexion {

	protected Shell shell;

	private Text txtLogin;
	private Text txtPassword;
	private Button btnConnexion;

	public Button getBtnConnexion() {
		return btnConnexion;
	}

	public Shell getShell() {
		return shell;
	}

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	/*
	 * public static void main(String[] args) { try { Connexion window = new
	 * Connexion(); window.open(); } catch (Exception e) { e.printStackTrace();
	 * } }
	 */

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	public void close() {
		shell.dispose();
	}

	/**
	 * @wbp.parser.entryPoint
	 */
	public void init() {
		createContents();
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell(SWT.CLOSE);
		shell.setSize(364, 242);
		shell.setText("SCRUMTOOL - Developed by TEAMSIO - version beta");
		shell.setImage(Utils.getImage(Utils.IMG_ICON));
		shell.setLayout(new FormLayout());
		shell.setBackground(Utils.COLOR_BAR_1);
		Composite composite = new Composite(shell, SWT.NONE);
		FormData fd_composite = new FormData();
		fd_composite.bottom = new FormAttachment(0, 75);
		fd_composite.right = new FormAttachment(100);
		fd_composite.top = new FormAttachment(0);
		fd_composite.left = new FormAttachment(0);
		composite.setLayoutData(fd_composite);
		composite.setBackgroundImage(Utils.getImage(Utils.IMG_LOGO));
		composite.setLayout(null);

		txtLogin = new Text(shell, SWT.BORDER);
		txtLogin.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		FormData fd_txtLogin = new FormData();
		fd_txtLogin.right = new FormAttachment(100, -50);
		txtLogin.setLayoutData(fd_txtLogin);
		txtLogin.setBackground(Utils.COLOR_BAR_2);

		txtPassword = new Text(shell, SWT.BORDER | SWT.PASSWORD);
		txtPassword.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		fd_txtLogin.bottom = new FormAttachment(txtPassword, -17);
		FormData fd_txtPassword = new FormData();
		fd_txtPassword.right = new FormAttachment(100, -50);
		fd_txtPassword.top = new FormAttachment(0, 131);
		txtPassword.setLayoutData(fd_txtPassword);
		txtPassword.setBackground(Utils.COLOR_BAR_2);

		Label lblIdentifiant = new Label(shell, SWT.NONE);
		fd_txtLogin.left = new FormAttachment(lblIdentifiant, 46);
		lblIdentifiant.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		lblIdentifiant.setFont(SWTResourceManager.getFont("Arial", 12, SWT.NORMAL));
		FormData fd_lblIdentifiant = new FormData();
		fd_lblIdentifiant.top = new FormAttachment(composite, 18);
		lblIdentifiant.setLayoutData(fd_lblIdentifiant);
		lblIdentifiant.setText("Identifiant :");
		lblIdentifiant.setBackground(Utils.COLOR_BAR_1);

		Label lblPassword = new Label(shell, SWT.NONE);
		fd_lblIdentifiant.left = new FormAttachment(lblPassword, 0, SWT.LEFT);
		fd_txtPassword.left = new FormAttachment(lblPassword, 17);
		lblPassword.setText("Mot de passe :");
		lblPassword.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		lblPassword.setFont(SWTResourceManager.getFont("Arial", 12, SWT.NORMAL));
		lblPassword.setBackground(Utils.COLOR_BAR_1);
		FormData fd_lblPassword = new FormData();
		fd_lblPassword.top = new FormAttachment(lblIdentifiant, 20);
		fd_lblPassword.right = new FormAttachment(100, -216);
		lblPassword.setLayoutData(fd_lblPassword);

		Composite composite_1 = new Composite(shell, SWT.NONE);
		composite_1.setBackground(Utils.COLOR_BAR_2);
		FormData fd_composite_1 = new FormData();
		fd_composite_1.top = new FormAttachment(txtPassword, 21);
		fd_composite_1.bottom = new FormAttachment(100);
		fd_composite_1.left = new FormAttachment(0);
		fd_composite_1.right = new FormAttachment(100);
		composite_1.setLayoutData(fd_composite_1);
		
		btnConnexion = new Button(composite_1, SWT.NONE);
		btnConnexion.setBounds(300, 10, 48, 25);
		btnConnexion.setText("Sign in");
		
	}

	public Text getTxtLogin() {
		return txtLogin;
	}

	public Text getTxtPassword() {
		return txtPassword;
	}
}
